# -*- coding: utf-8 -*-
import io
import sys
# sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8') #改变标准输出的默认编码

import csv
dict_mashup_to_api = {

}
with open("m-a_edges.csv", encoding='utf-8', mode="r", errors='ignore') as f:
    reader = csv.reader(f)
    for row in reader:
        if row[1] in dict_mashup_to_api:
            dict_mashup_to_api[row[1]] = dict_mashup_to_api[row[1]] + 1
        else:
            dict_mashup_to_api[row[1]] = 1

data = [dict_mashup_to_api]
with open('每个API被使用的次数.csv', "w", newline='', encoding='utf-8', errors='ignore') as f:
    writer = csv.writer(f)
    writer.writerow(['API名称', '使用次数'])
    for i in dict_mashup_to_api.items():
        data = [i[0], i[1]]
        writer.writerow(data)